'use strict';

angular.module('myApp.get_coupon', ['lumx']).controller('get_couponCtrl', ['$scope','$http','$routeParams',
	function($scope,$http,$routeParams){
		console.log($routeParams.id);

		var coupon_id = {'couponId':cardid};
		console.log(coupon_id);


		
	    $http.get('/consumer/'+userid+'/coupon/'+coupon_id).success(function(data){
	    	if (!data.error) {
	    		console.log(data);
	    		$scope.coupon = data.result[0];
           		 $("#content").after($scope.coupon.content );
	    	};
	    });

	    $http.post('/consumer/'+userid+'/coupon',coupon_id).success(function(data){
	    	if (!data.error) {
	    		alert("成功获取此优惠券！关注‘中华爱情网’服务号，可查看所有。");
	    	}else{
	    		if (data.message != "优惠券已存在") {
	    			alert(data.message);
	    		};
	    	};
	    });	

		$scope.go_back = function(){
				window.location.href = '#/mycards/0/0';	
			};
		};	
}]);